/**
 * @description 新增、编辑功能项组弹窗
 * @author 李艳
 */

import React, {Component} from 'react'
import {Form, Input, Modal} from 'antd';
import {appModuleConfig} from "../../../configs/CommonComponentsConfig";
import SearchTable from "../../../commons/components/SearchTable";

const FormItem = Form.Item;

class FeatureGroupModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            modalVisible: false,
            confirmLoading: false,
        }
    }

    handleClose = () => {
        this.props.form.resetFields();
    };

    componentDidMount() {
        this.props.onRef(this);

    }

    render() {
        const formItemLayout = {
            labelCol: {
                span: 8
            },
            wrapperCol: {
                span: 12
            },
        };

        const {confirmLoading, modalVisible, handleOk, handleCancel, defaultValue,isAdd} = this.props;
        const {getFieldDecorator} = this.props.form;
        let childId = "";
        let FormValue = defaultValue;
        let title = "编辑功能项组";
        if (isAdd) {
            title = "新增功能项组";
            FormValue = {}
        }
        return (
            <div>
                <Modal  title={title}
                       visible={modalVisible}
                       onOk={handleOk}
                       onCancel={handleCancel}
                       width={600}
                       afterClose={this.handleClose}
                       confirmLoading={confirmLoading}
                       maskClosable={false}
                >
                    <Form>
                        <FormItem
                            {...formItemLayout}
                            label="代码"
                        >
                            {getFieldDecorator('code', {
                                initialValue: FormValue.code ?FormValue.code:"",
                              rules: [{required: true, message: '请填写代码!',whitespace:true}]
                            })(
                                <Input/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="名称">
                            {getFieldDecorator('name', {
                                initialValue: FormValue.name ?FormValue.name:"",
                                rules: [{required: true, message: '请填写名称!'}]
                            })(
                                <Input/>
                            )}
                        </FormItem>
                        <FormItem
                            {...formItemLayout}
                            label="所属应用模块"
                        >
                            {getFieldDecorator('appModule.id', {
                                initialValue: FormValue.appModule?FormValue.appModule.id:"",
                                rules: [{required: true, message: '请选择所属应用模块!'}]
                            })(
                                <SearchTable config={appModuleConfig}/>
                            )}
                        </FormItem>
                        {/*以下为隐藏的formItem*/}
                        <FormItem
                            style={{display: "none"}}>
                            {getFieldDecorator('id', {
                                initialValue: FormValue.id ? FormValue.id : "",
                            })(
                                <Input disabled/>
                            )}
                        </FormItem>
                    </Form>
                </Modal>
            </div>
        );
    }
}

FeatureGroupModal = Form.create()(FeatureGroupModal);
export default FeatureGroupModal;
